package com.nuoniu.sibanyun.service.cms.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.SysCompany;
import com.nuoniu.sibanyun.entity.cms.CmsInfo;
import com.nuoniu.sibanyun.mapper.cms.CmsInfoMapper;
import com.nuoniu.sibanyun.service.ISysCompanyService;
import com.nuoniu.sibanyun.service.cms.ICmsInfoService;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 网站基本设置 服务实现类
 * </p>
 *
 * @author 小啊刚
 * @since 2021-08-10
 */
@Service
public class CmsInfoServiceImpl extends ServiceImpl<CmsInfoMapper, CmsInfo> implements ICmsInfoService {

    @Autowired
    private ISysCompanyService companyService;

    @Override
    public void saveInfo(CmsInfo cmsInfo) {
        Integer companyId = UserThreadLocal.get().getCompanyId();
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("company_id", UserThreadLocal.get().getCompanyId());
        wrapper.last("LIMIT 1");
        CmsInfo info = this.getOne(wrapper);

        if(info != null) {
            cmsInfo.setId(info.getId());
        }

        cmsInfo.setCompanyId(companyId);
        this.saveOrUpdate(cmsInfo);
    }

    @Override
    public CmsInfo getInfoByCode(String companyCode) {
        SysCompany company = companyService.getByCode(companyCode);
        return null;
    }
}
